package com.xx.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xx.entity.Dish;
import com.xx.mapper.DishMapper;
import com.xx.service.IDishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author myx
 * @since 2025-01-09
 */
@Service
public class DishServiceImpl implements IDishService {

    @Autowired
    private DishMapper dishMapper;

    /**
     * 获取所有菜品及其分类信息
     * @return 菜品和分类信息列表
     */
    @Override
    public List<Dish> getAllDishesWithCategory() {
        return dishMapper.getAllDishesWithCategory();
    }

    /**
     * 分页获取菜品及其分类信息
     * @param pageNum 当前页码
     * @param pageSize 每页大小
     * @return 分页信息
     */
    @Override
    public Page<Dish> getDishesWithCategoryPage(int pageNum, int pageSize,String dishName) {
        Page<Dish> page = new Page<>(pageNum, pageSize);
        List<Dish> dishList = dishMapper.getDishesWithCategoryPage(page,dishName);
        page.setRecords(dishList);
        return page;
    }

    /**
     * 新增菜品
     * @param dish 菜品对象
     */
    @Override
    public void addDish(Dish dish) {
        dishMapper.insertDish(dish);
    }

    /**
     * 通过菜名模糊查询菜品
     * @param name 菜名
     * @return 菜品列表
     */
    @Override
    public List<Dish> searchDishesByName(String name) {
        return dishMapper.searchDishesByName(name);
    }

    /**
     * 通过ID查询菜品信息
     * @param id 菜品ID
     * @return 菜品对象
     */
    @Override
    public Dish getDishById(Integer id) {
        return dishMapper.getDishById(id);
    }

    /**
     * 更新菜品信息
     * @param dish 菜品对象
     */
    @Override
    public void updateDish(Dish dish) {
        dishMapper.updateCategory(dish);
    }

    /**
     * 根据ID删除菜品
     * @param id 菜品ID
     */
    @Override
    public void delDishById(Integer id) {
        dishMapper.delDishById(id);
    }
}
